from behave import *


class Robot:
    def __init__(self, name):
        self.name = name
        self.status = 'on'
        self.enemy = ''

    def __repr__(self):
        return 'Robot %s' % self.name

    def alarm(self):
        self.status = 'alarm'

    def meet_enemy(self, target):
        self.enemy = target

    def shoot(self):
        return '%s shoot %s' % (self.name, self.enemy)

    def find_mine(self):
        self.status = 'mine_founded'

    def harvest(self):
        return '%s harvest mine' % self.name


@given('机器人处于警戒状态')
def step_impl(context):
    context.robot = Robot('龙骑兵')
    context.robot.alarm()


@when('机器人遇到敌人')
def step_impl(context):
    context.robot.meet_enemy('黑暗圣殿')
    assert len(context.robot.enemy) > 0


@then('机器人射击')
def step_impl(context):
    res = context.robot.shoot()
    assert 'shoot' in res


@given('机器人处于采集状态')
def step_impl(context):
    context.robot = Robot('收集者')
    context.robot.find_mine()


@then('机器人采集矿石')
def step_impl(context):
    res = context.robot.harvest()
    assert 'harvest' in res

